import sqlite3

import pymysql

conn = sqlite3.connect('database.db')
conn.row_factory = sqlite3.Row

# mysql_con = pymysql.connect(user="root",
#                             passwd="root",
#                             db="bangjiang",
#                             host="127.0.0.1",
#                             local_infile=1)

for i in range(0, 36):
    sql = "select * from gate_pass_info_device_{}".format(i)
    result = conn.execute(sql)
    table_name = 'gate_pass_info_device_{}'.format(i)
    with open(table_name, 'w', encoding='utf8') as f:
        for row in result:
            data = list(row)
            data[4] = str(data[4])
            line = ','.join(data)
            line += '\n'
            f.write(line)
    print('write result gate_pass_info_device_{}'.format(i))
